package com.trs.touch.event.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    MyView myView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myView = (MyView) findViewById(R.id.myview);
        myView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent ev) {
                switch (ev.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        System.out.println("MyView--OnTouchListener:" + "---MotionEvent.ACTION_DOWN---");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        System.out.println("MyView--OnTouchListener:" + "---MotionEvent.ACTION_MOVE---");
                        break;
                    case MotionEvent.ACTION_UP:
                        System.out.println("MyView--OnTouchListener:" + "---MotionEvent.ACTION_UP---");
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        System.out.println("MyView--OnTouchListener:" + "---MotionEvent.ACTION_CANCEL---");
                        break;
                    default:
                        break;
                }
                // returen true 表示不向下继续传递,false 则继续向下传递
                return false;
            }
        });
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                System.out.println("MainActivity--dispatchTouchEvent:" + "---MotionEvent.ACTION_DOWN---");
                break;
            case MotionEvent.ACTION_MOVE:
                System.out.println("MainActivity--dispatchTouchEvent:" + "---MotionEvent.ACTION_MOVE---");
                break;
            case MotionEvent.ACTION_UP:
                System.out.println("MainActivity--dispatchTouchEvent:" + "---MotionEvent.ACTION_UP---");
                break;
            case MotionEvent.ACTION_CANCEL:
                System.out.println("MainActivity--dispatchTouchEvent:" + "---MotionEvent.ACTION_CANCEL---");
                break;
            default:
                break;
        }
        // returen true 表示不向下继续传递,false 则继续向下传递
//        return false;
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                System.out.println("MainActivity--onTouchEvent:" + "---MotionEvent.ACTION_DOWN---");
                break;
            case MotionEvent.ACTION_MOVE:
                System.out.println("MainActivity--onTouchEvent:" + "---MotionEvent.ACTION_MOVE---");
                break;
            case MotionEvent.ACTION_UP:
                System.out.println("MainActivity--onTouchEvent:" + "---MotionEvent.ACTION_UP---");
                break;
            case MotionEvent.ACTION_CANCEL:
                System.out.println("MainActivity--onTouchEvent:" + "---MotionEvent.ACTION_CANCEL---");
                break;
            default:
                break;
        }
        // returen true 表示不向下继续传递,false 则继续向下传递
//        return false;
        return super.onTouchEvent(ev);
    }

}
